@extends('layouts.admin')
@section('style')

@endsection
@section('content')
    <section class="qrcodeSection clearfix">
        <div class="qrcodeDiv">
            @if(empty($error))
                <div class="qrcode-img box-center border-ef pd10" data-text="{{$url}}">
                </div>
            @else
                <div class="qrcode-img box-center border-ef pd10">
                    {{$error}}
                </div>
                <button class="btn btn-primary">刷新</button>
            @endif
        </div>
    </section>
@endsection
@section('script')
    <script>
		@if(empty($error))
        utils.qrcode($('.qrcode-img')[0], {height: 200, width: 200});
		var interval = setInterval(function () {
			$.get('/payment/payment/poll?order_id={{$orderId}}', function (res) {
				if (res != 'null') {
					if (res == 'paid') {
						var type = 'success';
					} else if (res == 'canceled') {
						var type = 'warning';
					} else if (res == 'Failed') {
						var type = 'error';
					}
					utils.showAlert(res, {'sub': '', 'type': type});
					clearInterval(interval);
					window.parent.location.href = '/web/prize/index'
				}
			});
		}, 3 * 1000);
		@else
            $('.btn').on('click', function () {
			location.href = '/payment/wechat/pay?order_id={{$orderId}}'
		});
        @endif
    </script>
@endsection